# Maintainer: Frederik Carlier <frederik.carlier@keysight.com>

_realname=gnustep-gui
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.32.0
pkgrel=2
pkgdesc="GNUstep GUI Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gnustep.github.io/'
msys2_repository_url='https://github.com/gnustep/libs-gui'
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnustep-base"
         "${MINGW_PACKAGE_PREFIX}-libffi"
         "${MINGW_PACKAGE_PREFIX}-giflib"
         "${MINGW_PACKAGE_PREFIX}-icu"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libtiff")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-clang"
             "${MINGW_PACKAGE_PREFIX}-lld"
             "${MINGW_PACKAGE_PREFIX}-gnustep-make"
             rsync)
source=("${msys2_repository_url}/releases/download/gui-${pkgver//./_}/${_realname}-${pkgver}.tar.gz")
sha256sums=('0c03a1b6313babd592ec58fcb825091f77eb27429a4ce4306ec3a7cfa7f9a1f6')

build() {
  rsync --recursive --times --links "${srcdir}/${_realname}-${pkgver}"/* "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  case ${MSYSTEM} in
    MINGW*|UCRT*)
      export LDFLAGS="-fuse-ld=lld -lstdc++ -lgcc_s"
      ;;
    CLANG*)
      export LDFLAGS="-lc++"
      ;;
  esac

  CC="$MINGW_PREFIX/bin/clang" \
  CXX="$MINGW_PREFIX/bin/clang++" \
  ./configure \
    --prefix="${MINGW_PREFIX}"
  
  CC="$MINGW_PREFIX/bin/clang" \
  CXX="$MINGW_PREFIX/bin/clang++" \
  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB"
}
